
import 'package:flame/components.dart';
import 'package:flame/flame.dart';
import 'package:flutter/material.dart';

@immutable class Suit {
  factory Suit.fromInt(int index) {
    assert(index>=0 && index<=3);
    return _singletons[index];
  }

  Suit._(this.value, this.label, double x, double y, double w, double h)
    : sprite = klondikeSprite(x, y, w, h);

  final int value;
  final String label;
  final Sprite sprite;

  static final List<Suit> _singletons = [
    Suit._(0, 'hearts', 1176, 17, 172, 183),
    Suit._(1, 'diamonds', 973, 14, 177, 182),
    Suit._(2, 'clubs', 974, 226, 184, 172),
    Suit._(3, 'spades', 1178, 220, 176, 182),
  ];

  bool get isRed => value <= 1;
  bool get isBlack => value >= 2;
}

  Sprite klondikeSprite(double x, double y, double width, double height) {
    return Sprite(
      Flame.images.fromCache('klondike-sprites.png'),
      srcPosition: Vector2(x, y),
      srcSize: Vector2(width, height),
    );
  }